/**
 * 
 */
package com.module.osr.ui.stormbringer.charcreator.widgets;

import com.ahq.main.H1SelectionBorder;
import com.dalonedrau.jogl.engine.GlobalConsts;
import com.dalonedrau.jogl.opengl.sprite.SpriteImageObjectFactory;
import com.dalonedrau.jogl.opengl.ui.Label;
import com.dalonedrau.jogl.opengl.ui.UIFactory;
import com.dalonedrau.jogl.opengl.ui.border.EmptyBorder;
import com.dalonedrau.jogl.opengl.ui.border.FlexibleImageBorder;
import com.dalonedrau.jogl.opengl.ui.border.GuiBorder;
import com.dalonedrau.jogl.opengl.ui.panel.Panel;
import com.dalonedrau.jogl.opengl.ui.panel.PortraitPagePanel;

/**
 * @author Donald
 */
public final class StepsPanel extends PortraitPagePanel {
	/** the arrow border. */
	private GuiBorder	bdrArrow	= new H1SelectionBorder();
	/** the empty border. 18px spacing on left and right. */
	private GuiBorder	bdrEmpty	= new EmptyBorder(
											0,
											GlobalConsts.INT_018,
											0,
											GlobalConsts.INT_018
											);
	/**
	 * Creates a new instance of {@link StepsPanel}.
	 * @throws Exception if an error occurs
	 */
	public StepsPanel() throws Exception {
		super(Panel.PORTRAIT_CENTER);
		System.out.println("StepsPanel");
		// each row will be a panel, 212px wide by 32px high
		// 160px width is used for labels, which are 19px high
		// remaining
		Panel pnl = getIndividualStepPanel();
		// GENDER - 96px wide by 19px high
		Label lbl = UIFactory.getInstance().getStandardH1Label("GENDER     ");
		lbl.setBorder(bdrArrow);
		pnl.addChild(lbl);
		super.addChild(pnl);
		// ATTRIBUTES - 160px wide by 19px high
		pnl = getIndividualStepPanel();
		lbl = UIFactory.getInstance().getStandardH1Label("ATTRIBUTES ");
		lbl.setBorder(bdrEmpty);
		pnl.addChild(lbl);
		super.addChild(pnl);
		// NATIONALITY - 160px wide by 19px high
		pnl = getIndividualStepPanel();
		lbl = UIFactory.getInstance().getStandardH1Label("NATIONALITY");
		lbl.setBorder(bdrEmpty);
		pnl.addChild(lbl);
		super.addChild(pnl);
		// CLASS - 160px wide by 19px high
		pnl = getIndividualStepPanel();
		lbl = UIFactory.getInstance().getStandardH1Label("CLASS      ");
		lbl.setBorder(bdrEmpty);
		pnl.addChild(lbl);
		super.addChild(pnl);

		pnl = null;
		lbl = null;
	}
	/**
	 * Highlghts a specific index.
	 * @param index the index being highlighted.  
	 * The index is always 1 less than the wizard's step.
	 */
	public void highlightIndex(final int index) {
		for (int i = 0; i < super.getChildren().length; i++) {
			// each child is a panel containing one label
			// set the label's border to empty
			((Panel) super.getChildren()[i]).getChildren()[0].setBorder(
					bdrEmpty);
		}
		int i = index - 1;
		if (i >= 0) {
			((Panel) super.getChildren()[i]).getChildren()[0].setBorder(
					bdrArrow);
		}
	}
	/**
	 * Gets an individual step panel for display.
	 * @return {@link Panel}
	 * @throws Exception if an error occurs
	 */
	private Panel getIndividualStepPanel() throws Exception {
		Panel pnl = new PortraitPagePanel(Panel.PORTRAIT_CENTER);
		pnl.setBorder(new FlexibleImageBorder(
						// bottom-left
						FlexibleImageBorder.BORDER00_BL_LEFT_FULL_BOTTOM_HALF,
						// bottom-right
						FlexibleImageBorder.BORDER05_BR_RIGHT_HALF_BOTTOM_HALF,
						// bottom
						FlexibleImageBorder.BORDER08_B_BOTTOM_HALF,
						// top-left
						FlexibleImageBorder.BORDER10_TL_LEFT_FULL_TOP_HALF,
						// top-right
						FlexibleImageBorder.BORDER15_TR_RIGHT_HALF_TOP_HALF, 
						// top
						FlexibleImageBorder.BORDER18_T_TOP_HALF,
						// left
						FlexibleImageBorder.BORDER21_L_LEFT_FULL,
						// right
						FlexibleImageBorder.BORDER22_R_RIGHT_HALF	
				));
		return pnl;
	}
}
